/// Creator:      fengliang
/// CreatDate:    2022-06-14
/// Description:  血袋记录
Class Nur.MNISV3.BloodBagRec Extends %Persistent
{

Relationship ChildRec As Nur.MNISV3.BloodBagSubRec [ Cardinality = children, Inverse = RecPref ];

/// 记录日期
Property RecDate As %Library.Date(FORMAT = 1) [ InitialExpression = {+$p($h,",",1)}, Required ];

/// 记录时间
Property RecTime As %Library.Time [ InitialExpression = {+$p($h,",",2)}, Required ];

/// 记录人
Property RecUser As %Library.String(TRUNCATE = 1);

/// LisId号
Property BloodPref As %Library.String(TRUNCATE = 1);

/// 血袋号
Property BloodBagNo As %Library.String(TRUNCATE = 1);

/// 血制品条码号
Property BloodProductNo As %Library.String(TRUNCATE = 1);

/// 血袋状态取血"G",接收"R",输血开始"S",输血巡视"T",输血暂停"SU",输血继续"C",输血结束"E",血袋已回收"RE":
Property Status As %Library.String(TRUNCATE = 1);

/// 就诊号
Property EpisodeId As %Library.String(TRUNCATE = 1);

/// 登记号
Property PatRegNo As %Library.String(TRUNCATE = 1);

/// 科室Id
Property LocId As %Library.String(TRUNCATE = 1);

/// 汇总单条码(取血单号)
Property GetBarCode As %Library.String(TRUNCATE = 1);

Index DateTime On (RecDate, RecTime);

Index Adm On EpisodeId;

Index DateAdm On (RecDate, EpisodeId);

Index RegNo On PatRegNo;

Index UserDr On (RecDate, RecUser);

Index LocDate On (RecDate, LocId);

Index GetBarCode On GetBarCode;

Index BloodPref On BloodPref;

Index BarCode On (BloodBagNo, BloodProductNo);

/// Creator:      fengliang
/// CreatDate:    2022-06-14
/// Description:  保存
/// other:        w ##class(Nur.MNISV3.BloodBagRec).Save("0010420211027","P0020","0010420211027^P0020","R",4113,1,114)
ClassMethod Save(bldbagno, bldproductno, bloodPref, status, episodeId, userId, locId, getBarCode = "", recDate = "", recTime = "")
{
    i recDate="" s recDate=+$h
    e  s recDate=##class(websys.Conversions).DateHtmlToLogical(recDate)
    i recTime="" s recTime=$P($H,",",2)
    e  s recTime=##class(websys.Conversions).TimeHtmlToLogical(recTime)
    s rw=$O(^Nur.MNISV3.BloodBagRecI("BarCode"," "_bldbagno," "_bldproductno,""))
    i bloodPref'="" s rw=$O(^Nur.MNISV3.BloodBagRecI("BloodPref"," "_bloodPref,""))
    if rw'=""
    {
        s a=##class(Nur.MNISV3.BloodBagRec).%OpenId(rw)
    }else{
        s a=##class(Nur.MNISV3.BloodBagRec).%New()
    }
    s paitentId=$p(^PAADM(episodeId),"^",1)
    s regNo=$p(^PAPER(paitentId,"PAT",1),"^",2)
    s a.BloodPref=bloodPref
    s a.BloodBagNo=bldbagno
    s a.BloodProductNo=bldproductno
    s a.Status=status
    s a.RecDate=recDate
    s a.RecTime=recTime
    s a.EpisodeId=episodeId
    s a.PatRegNo=regNo
    s a.LocId=locId
    s a.RecUser=userId
    s a.GetBarCode=getBarCode
    s sc=a.%Save()
    s id=a.%Id()
    d a.%Close()
    q:$$$ISERR(sc) "err:"_$SYSTEM.Status.GetErrorText(sc)
    q id
}

Storage Default
{
<Data name="BloodBagRecDefaultData">
<Value name="1">
<Value>%%CLASSNAME</Value>
</Value>
<Value name="2">
<Value>RecDate</Value>
</Value>
<Value name="3">
<Value>RecTime</Value>
</Value>
<Value name="4">
<Value>RecUser</Value>
</Value>
<Value name="5">
<Value>BloodPref</Value>
</Value>
<Value name="6">
<Value>BloodBagNo</Value>
</Value>
<Value name="7">
<Value>BloodProductNo</Value>
</Value>
<Value name="8">
<Value>Status</Value>
</Value>
<Value name="9">
<Value>EpisodeId</Value>
</Value>
<Value name="10">
<Value>PatRegNo</Value>
</Value>
<Value name="11">
<Value>LocId</Value>
</Value>
<Value name="12">
<Value>GetBarCode</Value>
</Value>
</Data>
<DataLocation>^Nur.MNISV3.BloodBagRecD</DataLocation>
<DefaultData>BloodBagRecDefaultData</DefaultData>
<IdLocation>^Nur.MNISV3.BloodBagRecD</IdLocation>
<IndexLocation>^Nur.MNISV3.BloodBagRecI</IndexLocation>
<StreamLocation>^Nur.MNISV3.BloodBagRecS</StreamLocation>
<Type>%Storage.Persistent</Type>
}

}
